
var admin = [];
var startDate = '';
var endDate = '';
var adminid = 0;
var List = [];

//分页查询
var limit = 5;// 每页多少条
var currPage = 1;// 当前页
var allPage = 1;// 总页数
var count = 0;// 默认共多少条数据

function getstartDate(){
    startDate = document.getElementById('start').value;
    console.log(startDate);
	
}
function getendDate(){
	endDate = document.getElementById('end').value;
	console.log(endDate);
}



selectLog();
function selectLog(){
	console.log(adminid);
	console.log(startDate);
	console.log(endDate);
	
	$.ajax({
		url:ajax_host+'selectadminlog.act',
        dataType:'JSON',
        data:{
            aid : adminid,
            start : startDate,
			end : endDate,
			startpage : currPage,
			limitpage : limit    
		},
    	success:function(resp){
            
    		if(resp.success){
                List = resp.list;
				console.log("列表："+List);
                // getlist()
				renderTable(resp.list);
				// 总页数=记录数/每页记录
				count = resp.count;
				console.log('总记录数:'+count)
				allPage=count%limit==0?(count/limit):(parseInt(count/limit+1));
				console.log('总页数:'+allPage);
				$("#pager").html(currPage+"/"+allPage);
    		}else{
                layer.alert('获取文件类型失败')
            }
    	},
    	
    });
}


function renderTable(arr){
	var str = `<tr>
		<th>管理员id</th>
		<th>操作内容</th>
		<th>所操作的列表</th>
		<th>操作时间</th>
		<th>操作</th>	
	</tr>`;
	for(var i = 0;i<arr.length;i++){
		var a = arr[i];
		str += 
		   `<tr>
            <td>${a.aId}</td>
			<td>`;
			if(a.cId == 1) str +='添加数据';
			if(a.cId == 2) str +='删除数据';
			if(a.cId == 3) str +='修改数据';
			if(a.cId == 4) str +='查询数据';
			if(a.cId == 5) str +='审核快件';
			if(a.cId == 6) str +='寄送';
			if(a.cId == 7) str +='退单';
			if(a.cId == 8) str +='寄送失败';
			str +=`</td>
			<td>${a.url}</td>
			<td>${a.cTime}</td>
			<th>
			<a href = "###" onclick="del(${a.lid})">删除</a>
			</th>
		</tr>`;
		
	}
	html('table',str);
}



getadmin();
function getadmin(){
	$.ajax({
		url : ajax_host +'getadminName.act',
		dataType:'JSON',
		
		success:function(resp){
			if(resp.success){
				admin = resp.list;
				console.log("列表："+admin);
				renderType(admin)
			}
		}
	})
}
function renderType(arr){
    var str = '<option value="0">请选择</option>';
    for(var i = 0; i<arr.length;i++){
		str+=`<option  value="${arr[i].adminId}">${arr[i].adminName}</option>`;
	}
	html('admin',str);
}
function change(){
    adminid = val('admin');
    console.log('管理员id：'+adminid);
}



//给删除按钮挂事件
function del(lid){
	console.log('列表删除'); 
	layer.confirm("确定删除该用户吗？", {
		btn: ['确定','取消'] //按钮
	   ,skin: 'layui-layer-lan'
	   ,closeBtn: 0
	   ,anim: 3 //动画类型
   },function(){

	// var user = List[index];
	// //空指针的判断
	// console.log('判断'+user)
	// if(!user || user.logId <=0){
	// 	return;
	// }
	$.ajax({
		url:ajax_host+'LogDel.act',
		type:'post',
		dataType:'JSON',
		data:{
			lid : lid
		},
	success:function(resp){
		if(resp.success){
			//删除数组的元素
			layer.alert('删除成功');
			
			selectLog();
			
		}else{
			layer.alert(resp.errmsg);
		}
		
	}
	})


   });
		
	
}
function pagenext() {
	if (currPage + 1 > allPage) {
		layer.alert("当前已经是最后一页");
		return;
	}
	
	currPage = currPage + 1;
	selectLog();
};

function pageback() {
	if (currPage - 1 == 0) {
		layer.alert("当前已经是第一页");
		return;
	}
	
	currPage = currPage - 1;
	selectLog();
};

